<?php
namespace app\admin\controller\article;

use app\admin\service\article\ArticleService;
use app\common\controller\AdminBase;
use app\common\model\Article as ArticleModel;
use think\facade\Db;

/**
 * 文章列表
 * 列表 添加 修改 删除等
*/
class Article extends AdminBase{
    /**
     * 列表
     */
    public function article_list(){
        $params = reqDecode();//获取并参数解密
        $model = new ArticleModel();
        $list = $model->withSearch($this->searchFields($params),$this->searchData($params))->with('ArticleCate')
            ->field('id,cate_id,state,title,description,thumb,text,sort')
            ->order('id','desc')
            ->paginate($params['limit'], false)->toArray();
        return suc('成功',$list);
    }
    /**
     * 添加
    */
    public function article_add(){
        $params = reqDecode();//获取并参数解密
//        print_r($user);exit;
       if(!empty($params) && !empty($params['title'])){
          $res = ArticleService::saveOrEditUser($params,$this->admin->id);
          return  $res;
       }
       return suc('非法访问','',1);
    }
}
